﻿''' <summary>
''' Page that demonstrates how to use NavFx to implement a Wizard
''' </summary>
Partial Public Class Wizard
	Inherits NavFx.HostPage

#Region "Private members"

	''' <summary>
	''' Tracks index of current page
	''' </summary>
	Private currentIndex As Integer = 0

	''' <summary>
	''' Reference to the component handling transitions from page to page
	''' </summary>
	Private navTransitor As SimpleTransitor = Nothing


	''' <summary>
	''' Helper method ti set state of the buttons based on the current page
	''' </summary>
	Private Sub setButtonState()

		Me.previousPage.IsEnabled = (Me.currentIndex <> 0)
		Me.nextPage.IsEnabled = (Me.currentIndex <> 2)
		Me.finishWizard.IsEnabled = (Me.currentIndex = 2)

	End Sub


	''' <summary>
	''' Helper method to navigate the application home page
	''' </summary>
	Private Sub goHome()

		Me.navTransitor.Target = Application.Current
		Me.Navigator.GoToPage("Home")
	End Sub

#End Region

#Region "Constructors"

	''' <summary>
	''' Default constructor
	''' </summary>
	Public Sub New()

		'capture a reference to the component that handles
		'transition from page to page
		Me.navTransitor = Me.Navigator.GetTransitor(Of SimpleTransitor)()

		InitializeComponent()
	End Sub

#End Region

#Region "Event handlers"

	''' <summary>
	''' Navigate to previous page
	''' </summary>
	Private Sub previous_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles previousPage.Click

		'display the appropriate page
		Select Case Me.currentIndex

			Case Is = 1
				Me.Navigator.GoToPage("WizardPage1")
			Case Is = 2
				Me.Navigator.GoToPage("WizardPage2")
			Case Else
		End Select

		'make sure the index is valid
		Me.currentIndex = Me.currentIndex - 1
		If Me.currentIndex < 0 Then
			Me.currentIndex = 0
		End If

		'update state of buttons
		Me.setButtonState()
	End Sub

	''' <summary>
	''' Navigate to next page
	''' </summary>
	Private Sub next_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles nextPage.Click

		'display the appropriate page
		Select Case Me.currentIndex

			Case Is = 0
				Me.Navigator.GoToPage("WizardPage2")
			Case Is = 1
				Me.Navigator.GoToPage("WizardPage3")
			Case Else
		End Select

		'make sure the index is valid
		Me.currentIndex = Me.currentIndex + 1
		If Me.currentIndex > 2 Then

			Me.currentIndex = 2
		End If

		'update state of buttons
		Me.setButtonState()
	End Sub

	''' <summary>
	''' Return the application home page on click of the finish button
	''' </summary>
	Private Sub finish_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles finishWizard.Click

		Me.goHome()

	End Sub

	''' <summary>
	''' Return to the application home page on click of the cancel button
	''' </summary>
	Private Sub cancel_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles cancelWizard.Click

		Me.goHome()
	End Sub

	''' <summary>
	''' Load the first page of the wizard on loading of this page
	''' </summary>
	Private Sub Wizard_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded

		'set target for transitions within the page
		'this will not need to be set again until
		'either the finish or cancel buttons are clicked
		Me.navTransitor.Target = Me.pageContainer
		Me.Navigator.GoToPage("WizardPage1")
	End Sub

#End Region
End Class
